package javasrc;

/**
 * Write a function that takes a string as input and returns
 * the string reversed.
 *
 * Example:
 * Given s = "hello", return "olleh".
 */

public class ReverseString {
    // Time:  O(n)
    // Space: O(n)
    public String reverseString(String s) {
        char[] chars = s.toCharArray();
        int i = 0, j = s.length() - 1;
        while (i < j) {
            char tmp = chars[i];
            chars[i] = chars[j];
            chars[j] = tmp;
            i++;
            j--;
        }
        return new String(chars);
    }
}
